<?php


/**
 * Notes:
 * PROJECT_NAME : ERP v1.0.0.042823
 * User: 夏鱼儿<397072174@qq.com>
 * Date: 2023/5/15
 * Time: 19:40
 */

namespace app\model;

use think\Model;

class AccountManage extends Model
{


    /**
     * 分账
     * @param $userId
     * @param $amount
     * @return mixed
     */
    public static function updateAccount($userId, $amount, $type = 3)
    {
        return self::where('user_id', $userId)
                   ->where('type', $type)
                   ->inc('current_money', $amount)
                   ->inc('total_income', $amount)
                   ->dec('settlement_money', $amount)
                   ->save();
    }


    /**
     * 构造器
     * @param $value
     * @return string
     */
    public function getTypeTextAttr($value, $data)
    {
        $types = [1 => '司机', 2 => '公司', 3 => '平台', 4 => '渠道'];
        return $types[$data['type']];
    }

    /**
     * 构造器
     * @param $value
     * @return string
     */
    public function getStatusTextAttr($value, $data)
    {
        $status = [1 => '正常', 2 => '删除'];
        return $status[$data['status']];
    }
}